package com.tobeface.wechat.showcase.handler;

import com.tobeface.modules.lang.Strings;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.WeChatMessageChannel;
import com.tobeface.wechat.message.handler.TextMessageHandlerSupport;

/**
 * @author loudyn
 */
public class HelloWorldMessageHandler extends TextMessageHandlerSupport {

    @Override
    protected boolean isTextMessageSupport(WeChatMessage message, String content) {
        return !Strings.isBlank(content) && content.contains("hello");
    }

    @Override
    protected void onTextMessageReceived(WeChatMessageChannel channel,
                                         WeChatMessage message,
                                         String content) {

        WeChatMessage outMessage = WeChatMessageBuilder.replyText(message).content("hello world").build();
        channel.writeMessage(outMessage);
        channel.flush();
    }

    @Override
    public int getPriority() {
        return HIGH_PRIORITY;
    }
}
